using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Be.Windows.Forms;

namespace Tim2
{
    public partial class FormFind : Form
    {
        public FormFind()
        {
            InitializeComponent();

            hexBox.ByteProvider = new DynamicByteProvider(new ByteCollection());
        }

        public byte[] GetFindBytes()
        {
            if (rbString.Checked)
            {
                byte[] res = System.Text.ASCIIEncoding.ASCII.GetBytes(txtString.Text);
                return res;
            }
            else
            {
                return ((DynamicByteProvider)hexBox.ByteProvider).Bytes.GetBytes();
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (rbString.Checked && txtString.Text.Length == 0)
                DialogResult = DialogResult.Cancel;
            else if (rbHex.Checked && hexBox.ByteProvider.Length == 0)
                DialogResult = DialogResult.Cancel;
            else
                DialogResult = DialogResult.OK;
        }

        private void rbString_CheckedChanged(object sender, EventArgs e)
        {
            txtString.Enabled = rbString.Checked;
            hexBox.Enabled = !txtString.Enabled;

            if (txtString.Enabled)
                txtString.Focus();
            else
                hexBox.Focus();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}